package com.climber.spb_rabbitmq.manualack;

import com.climber.spb_rabbitmq.utils.RabbitMQUtils;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.MessageProperties;

import java.nio.charset.StandardCharsets;
import java.util.Scanner;

public class MProducer1 {
    private static final String TASK_QUEUE_NAME="ack_queue_durable";

    public static void main(String[] args) {
        try(
                Channel channel = RabbitMQUtils.getChannel();
        ){
//            第二个参数表示是否队列持久化,也就是服务重启后队列依旧存在
                channel.queueDeclare(TASK_QUEUE_NAME,true,false,false,null);
//                channel.queueDeclare(TASK_QUEUE_NAME,false,false,false,null);
            Scanner scanner = new Scanner(System.in);
            System.out.println("the message ready to send is ...");

            while (scanner.hasNext()) {
//                channel.basicPublish("", TASK_QUEUE_NAME, null, scanner.next().getBytes(StandardCharsets.UTF_8));
//                消息持久化,重启后依旧存在
                channel.basicPublish("", TASK_QUEUE_NAME, MessageProperties.PERSISTENT_TEXT_PLAIN, scanner.next().getBytes(StandardCharsets.UTF_8));
                System.out.println("the message ready to send is ...");
            }

        }catch (Exception e){
            e.printStackTrace();
        }
    }

}
